﻿using Newtonsoft.Json;

namespace Kz.Telegram.Bot.Infrastructure.Extensions
{
    public static class ObjectExtension
    {
        public static string ToJson(this object obj)
        {
            if (obj == null)
            {
                return null;
            }
            return JsonConvert.SerializeObject(obj);
        }

        public static bool IsEmptyOrNull(this object thisValue)
        {
            return !thisValue.IsNotEmptyOrNull();
        }

        public static bool IsNotEmptyOrNull(this object thisValue)
        {
            return ObjToString(thisValue) != "" && ObjToString(thisValue) != "undefined" && ObjToString(thisValue) != "null";
        }

        public static string ObjToString(this object thisValue)
        {
            if (thisValue != null) return thisValue.ToString().Trim();
            return "";
        }
    }
}
